package com.along.htybrowser;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.along.htybrowser.greendao.dao.DaoMaster;
import com.along.htybrowser.greendao.dao.DaoSession;
import com.along.htybrowser.utils.AutoLog;

import org.greenrobot.greendao.query.QueryBuilder;

/**
 * @author wen66to88@163.com
 * @date 2021/7/9 - 16:03
 */
public class App extends Application {
    private static App app;
    private final boolean isDebug = true;//调试总开关

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AutoLog.IS_DEBUG = isDebug;
        initGreenDao();
    }

    /**
     * 初始化GreenDao,直接在Application中进行初始化操作
     */
    private void initGreenDao() {
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "htyBrowser.db");
        SQLiteDatabase db = helper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
        //打印日志
        QueryBuilder.LOG_SQL = true;
        QueryBuilder.LOG_VALUES = true;
    }

    private DaoSession daoSession;

    public DaoSession getDaoSession() {
        return daoSession;
    }

    public static App getInstance() {
        return app;
    }
}
